package gameEngine.com.state;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint.Style;
import android.view.KeyEvent;
import android.view.MotionEvent;
import gameEngine.com.*;
import gameEngine.com.Actor.Actor;

public class StateIGM extends MainActivity {

	public static int[] menu = { R.string.STRING_RESUME, R.string.STRING_MAP, R.string.STRING_OPTION, R.string.STRING_HELP, R.string.STRING_MAINMENU, R.string.STRING_EXIT };
	public static int menuTopX = 370;
	public static int menuTopY = 100;
	public static int menuElementWidth = 270;
	public static int menuElementHeight = 55;
	public static int menuElementSpace = 10;
	public static int menuTouchOffsetX = -137;
	public static int menuTouchOffsetY = -27;
	public static int menuTextOffsetX = 0;
	public static int menuTextOffsetY = 0;

	// String mess = getResources().getString(R.string.mess_1)
	public static void SendMessageStateIGM(int type) {
		switch (type) {
		case MESSAGE_CTOR:
			isGamePause = true;
			if (spriteMenuButton == null)
				spriteMenuButton = new Sprite("sprite/ui/menubutton.spr", true);
			StateConfirm.setConfirmDeActive();
			break;
		case MESSAGE_UPDATE:
			if (StateConfirm.isConfirm) {
				StateConfirm.SendMessageStateConfirm(MESSAGE_UPDATE);
				return;
			}
			for (int i = 0; i < menu.length; i++) {
				if (isTouchReleaseInRect(menuTopX + menuTouchOffsetX, menuTopY + menuTouchOffsetY + i * (menuElementHeight + menuElementSpace), menuElementWidth, menuElementHeight)) {
					switch (menu[i]) {
					case R.string.STRING_RESUME:
						isGamePause = false;
						mCurrentState = STATE_GAMEPLAY;
						resetTouch();
						resetKey();
						break;
					case R.string.STRING_HELP:
						changeState(STATE_HELP);
						break;
					case R.string.STRING_MAINMENU:
						StateConfirm.setConfirmActive(R.string.STRING_MAINMENU_CONFIRM);
						break;
					case R.string.STRING_EXIT:
						StateConfirm.setConfirmActive(R.string.STRING_EXIT_COFIRM);
						break;
					}
				}
			}
			break;
		case MESSAGE_PAINT:
			mainCanvas.drawColor(Color.BLACK);
			StateGameplay.SendMessageGameplay(MESSAGE_PAINT);
			mainCanvas.drawColor(0xAd222222);
			for (int i = 0; i < menu.length; i++) {
				if (!StateConfirm.isConfirm && isTouchDrapInRect(menuTopX + menuTouchOffsetX, menuTopY + menuTouchOffsetY + i * (menuElementHeight + menuElementSpace), menuElementWidth, menuElementHeight)) {
					spriteMenu.drawAFrame(mainCanvas, 1, menuTopX, menuTopY + i * (menuElementHeight + menuElementSpace));
				} else if (spriteMenuButton != null && mainCanvas != null)
					spriteMenu.drawAFrame(mainCanvas, 0, menuTopX, menuTopY + i * (menuElementHeight + menuElementSpace));
				fontsmall.drawString(mainCanvas, mainGameLib.getResources().getString(menu[i]), menuTopX, menuTopY + i * (menuElementHeight + menuElementSpace), BitmapFont.ALIGN_CENTER);
			}

			if (StateConfirm.isConfirm)
				StateConfirm.SendMessageStateConfirm(MESSAGE_PAINT);
			break;
		case MESSAGE_DTOR:
			break;
		}
	}
}
